home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / run-all-tests.z / run-all-tests
Encoding:
Text File  |  1999-10-18  |  5.7 KB  |  265 lines

  1. #!/bin/perl5
  2. #
  3. # This program runs all test that starts with 'test-' and sums
  4. # the results that the program prints.
  5. # Each time result should be of the form:
  6. # Time for|to KEYWORD (number_of_runs) 'other info': timestr()
  7. #
  8. # All options to this script is passed to all test program.
  9. # useful options:
  10. # --fast --force --lock-tables
  11. # --server   ==> mysql (default) / mSQL / Pg (postgres) / Solid
  12. # --user     ==> the user with permission to create / drop / select
  13. # --pass     ==> password for the user
  14. # --cmp      ==> Compare --server with one of the others (mysql/mSQL/Pg/Solid)
  15. # --comments ==> everything you want to say such as the extra options you
  16. #                gave to the db server. (use --comments="xxx xxx xxx"
  17. # --machine  ==> Give a OS/machine id for your logfiles.
  18. # --log         ==> puts output in output/RUN-server-machine-cmp-$opt_cmp
  19.  
  20. use DBI;
  21.  
  22. $opt_silent=1;            # Don't write header
  23. $prog_args=join(" ",@ARGV);
  24. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  25. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  26. $opt_silent=0;
  27. $perl=$^X;
  28. $machine=machine();
  29. $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
  30. $dir= ($pwd =~ /\\/) ? '\\' : '/';    # directory symbol for shell
  31.  
  32. $prog_count=$errors=0;
  33.  
  34. if ($opt_cmp) {
  35.     $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
  36. } else {
  37.     $filename = "$opt_server$opt_suffix-" . machine_part();
  38. }
  39.  
  40. if (! -d $opt_dir)
  41. {
  42.   if (-e $opt_dir)
  43.   {
  44.     die "$opt_dir isn't a directory\n";
  45.   }
  46.   mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
  47. }
  48.  
  49. if ($opt_skip_test) {
  50.   (@skip_tests) = split(/,\s*/, $opt_skip_test);
  51. }
  52.  
  53. if ($opt_old_headers)
  54. {
  55.   read_headers("$opt_dir/RUN-$filename");
  56. }
  57. else
  58. {
  59.   $server_version=$server->version();
  60. }
  61.  
  62. if (!$opt_log)
  63. {
  64.   open(LOG,">&STDOUT");
  65. }
  66. else
  67. {
  68.   open(LOG, "> $opt_dir/RUN-$filename") ||
  69.     die "Can't write to $opt_dir/RUN-$filename: $!\n";
  70. }
  71.  
  72. select(LOG);
  73. $|=1;
  74.  
  75. print "Benchmark DBD suite: $benchmark_version\n";
  76. print "Date of test:        $date\n";
  77. print "Running tests on:    $machine\n";
  78. print "Arguments:           $log_prog_args\n";
  79. print "Comments:            $opt_comments\n";
  80. print "Limits from:         $opt_cmp\n";
  81. print "Server version:      $server_version\n\n";
  82.  
  83.  
  84. $estimated=$warning=$got_warning=0;
  85. while (<test-*>)
  86. {
  87.   next if (/\.sh$/);        # configure script
  88.   next if (/\-fork$/);        # test script
  89.   $prog_count++;
  90.   /test-(.*)$/;            # Remove test from name
  91.   $prog=$1;
  92.   $skip_prog = 0;
  93.   foreach $skip_this (@skip_tests) {
  94.     if ($prog =~ /$skip_this/i) {
  95.       $skip_prog = 1;
  96.       last;
  97.     }
  98.   }
  99.   print "$prog: ";
  100.   if ((!$opt_use_old_results) && (!$skip_prog))
  101.   {
  102.     system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect") &&
  103.       printf STDERR "Warning: Can't execute $prog.  Check the file '$opt_dir$dir$prog-$filename'\n";
  104.   }
  105.   open(TEST,"$opt_dir/$prog-$filename");
  106.   $last_line="";
  107.   while(<TEST>)
  108.   {
  109.     chomp;
  110.     $last_line=$_ if (!(/^\s*$/));        # Search after last line
  111.   }
  112.   if ($last_line =~ /Total time:/i)
  113.   {
  114.     print $last_line . "\n";
  115.     open(TEST,"$opt_dir/$prog-$filename");
  116.     while (<TEST>)
  117.     {
  118.       if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*(\d*) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
  119.       {
  120.     $arg=$summa{$3};
  121.     if (!defined($arg))
  122.     {
  123.       $summa{$3}= [ $4,$6,$7,$8,$9,""];
  124.     }
  125.     else
  126.     {
  127.       $arg->[0]+=$4;
  128.       $arg->[1]+=$6;
  129.       $arg->[2]+=$7;
  130.       $arg->[3]+=$8;
  131.       $arg->[4]+=$9;
  132.     }
  133.     $prog_sum[0]+=$4;
  134.     $prog_sum[1]+=$6;
  135.     $prog_sum[2]+=$7;
  136.     $prog_sum[3]+=$8;
  137.     $prog_sum[4]+=$9;
  138.     if (length($1))
  139.     {
  140.       $summa{$3}->[5].="+";
  141.       $estimated=1;
  142.     }
  143.     if ($got_warning)
  144.     {
  145.       $summa{$3}->[5].="?";
  146.       $warning=1;
  147.       $got_warning=0;
  148.     }
  149.       }
  150.       elsif (/^warning/i)
  151.       {
  152.     $got_warning=1;
  153.       }
  154.       else
  155.       {
  156.     $got_warning=0;
  157.       }
  158.     }
  159.     if ($opt_debug)
  160.     {
  161.       print "Summary for $prog: ", join(" ",@prog_sum), "\n";
  162.     }
  163.   }
  164.   else
  165.   {
  166.     $errors++;
  167.     print "Failed ($opt_dir/$prog-$filename)\n";
  168.   }
  169. }
  170.  
  171. print "\n";
  172. if (!$errors)
  173. {
  174.   print "All $prog_count test executed successfully\n";
  175. }
  176. else
  177. {
  178.   print "Of $prog_count tests, $errors tests didn't work\n";
  179. }
  180. if ($estimated)
  181. {
  182.   print "Tests with estimated time have a + at end of line\n"
  183. }
  184. if ($warning)
  185. {
  186.   print "Tests with didn't return the correct result have a ? at end of line\n";
  187. }
  188.  
  189. if (%summa)
  190. {
  191.   @total=(0,0,0,0,0,"");
  192.   print "\nTotals per operation:\n";
  193.   print "Operation             seconds     usr     sys     cpu   tests\n";
  194.   foreach $key (sort(keys %summa))
  195.   {
  196.     $arg=$summa{$key};
  197.     printf("%-20.20s %8d %7.2f %7.2f %7.2f %7d %s\n",
  198.        $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
  199.        $arg->[5]);
  200.  
  201.     for ($i=0 ; $i < 5 ; $i++)
  202.     {
  203.       $total[$i]+=$arg->[$i];
  204.     }
  205.     $total[5].=$arg->[$i];
  206.   }
  207.   printf("%-20.20s %8d %7.2f %7.2f %7.2f %7d %s\n",
  208.      "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
  209.      $total[5]);
  210. }
  211.  
  212. select(STDOUT);
  213. if ($opt_log)
  214. {
  215.   print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
  216. }
  217.  
  218.  
  219. #
  220. # Read headers from an old benchmark run
  221. #
  222.  
  223. sub read_headers
  224. {
  225.   my ($filename)=@_;
  226.  
  227.   # Clear current values
  228.   $benchmark_version=$date=$machine=$server_version="";
  229.  
  230.   open(TMP, "<$filename") || die "Can't open $filename\n";
  231.   while (<TMP>)
  232.   {
  233.     chop;
  234.     if (/^Benchmark DBD.*:\s+(.*)$/)
  235.     {
  236.       $benchmark_version=$1;
  237.     }
  238.     elsif (/^Date of.*:\s+(.*)/)
  239.     {
  240.       $date=$1;
  241.     }
  242.     elsif (/^Running.*:\s+(.*)$/)
  243.     {
  244.       $machine=$1;
  245.     }
  246.     elsif (/^Arguments.*:\s+(.*)$/)
  247.     {
  248.       $log_prog_args=$1;
  249.     }
  250.     elsif (/^Comments.*:\s+(.*)$/)
  251.     {
  252.       $opt_comments=$1;
  253.     }
  254.     elsif (/^Limits.*:\s+(.*)$/)
  255.     {
  256.       $opt_cmp=$1;
  257.     }
  258.     elsif (/^Server ver.*:\s+(.*)$/)
  259.     {
  260.       $server_version=$1;
  261.     }
  262.   }
  263.   close(TMP);
  264. }
  265.